Tuesday, November 23, 2004

Serialization Constructor

For your class to be serialized by Xml Serializer it is needed that it has a
default constructor... For your class, if you only have a constructor which
takes some fixed arguments and does not have a constructor which takes in no
arguments the serializer is not able to create an instance of your class to
serialize and so it fails with an error..

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: ApplicationName.ClassName cannot be serialized
because it does not have a default public constructor.

Similarly error might also occur in case you are using Activator class's
Create instance method for some type which does not have default public
constructor and you are not passing the constructor parameters...

So in short if it is not harming the base functionality it is always good to
have default constructor for your class...

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

0 Comments:

Post a Comment

<< Home